<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

use Illuminate\Support\Facades\Route;

/**
 * 前端路由设置
 */

/* 多语言切换 */
Route::get('/locale/{locale}', 'LocaleController@lang')->name('locale');
/* 微信支付回调路由 */
Route::any('/wxpay/notify', 'WxPayController@notify')->name('wxpay.notify');

Route::get('/', function () {
    return redirect()->route('admin.login');
});
//文件下载
Route::get('download/{hash}', 'LocaleController@download')->name('download');

/*test*/
Route::get('/test/index', 'TestController@index')->name('test');
Route::get('/test/test', 'TestController@test');

/**
 * 教师端路由。
 */
Route::group(['prefix' => 'wechat', 'namespace' => 'Wechat', 'as' => 'wechat.'], function () {

    //无验证
    Route::match(['get', 'post'], 'token/checktoken', 'TokenController@checkToken')->name('token.checktoken');

    /* 登录 */
    Route::get('/login', 'LoginController@index')->name('login');
    Route::post('/login', 'LoginController@login');


    Route::post('/login/sms', 'LoginController@sendSms')->name('login.sms');

    /* 注册 */
    Route::get('/register', 'RegisterController@first')->name('register');
    Route::post('/register', 'RegisterController@saveFirst');

    //Route::group(['middleware' => ['web', 'official.test', 'wechat.oauth:default,snsapi_userinfo']], function () {
    Route::group(['middleware' => ['web', 'teacher.auth']], function () {

        //首页
        Route::get('/home', 'HomeController@index')->name('home');

        /* 个人中心 */
        Route::get('/profile/index', 'ProfileController@index')->name('profile');
        Route::match(['get', 'post'], '/profile/edit', 'ProfileController@edit')->name('profile.edit');
        Route::get('/logout', 'LoginController@logout')->name('logout');

        /* 密码修改 */
        Route::match(['get', 'post'], '/profile/password', 'ProfileController@password')->name('profile.password');

        /*学生管理*/
        Route::get('/child/index', 'ChildController@index')->name('child.index');
        Route::match(['get', 'post'], '/child/add', 'ChildController@add')->name('child.add');
        Route::match(['get', 'post'], '/child/edit/{id}', 'ChildController@edit')->name('child.edit');
        Route::get('/child/delete/{id}', 'ChildController@delete')->name('child.delete');
        Route::get('/child/view/{id}', 'ChildController@view')->name('child.view');

        /* 评估测试管理 */
        Route::get('/assessment/result', 'AssessmentController@result')->name('assessment.result');
        Route::get('/assessment/index/{child_id}', 'AssessmentController@index')->name('assessment.index');
        Route::match(['get', 'post'], '/assessment/add/{child_id}', 'AssessmentController@add')->name('assessment.add');
        Route::match(['get', 'post'], '/assessment/edit/{id}', 'AssessmentController@edit')->name('assessment.edit');
        Route::get('/assessment/delete/{id}', 'AssessmentController@delete')->name('assessment.delete');
        Route::get('/assessment/view/{id}', 'AssessmentController@view')->name('assessment.view');
        Route::get('/assessment/ajaxdata/{child_id?}', 'AssessmentController@ajaxdata')->name('assessment.ajaxdata');

        /*训练结果*/
        Route::get('/training/index', 'TrainingController@index')->name('training.index');
        Route::get('/training/view/{id}', 'TrainingController@view')->name('training.view');
        Route::get('/training/delete/{id}', 'TrainingController@delete')->name('training.delete');
        Route::get("/training/child/{child_id}", "TrainingController@child")->name('training.child');
        Route::get("/training/getchilddata/{child_id}", "TrainingController@getchilddata")->name('training.getchilddata');

        /*训练统计*/
        /*成功失败次数*/
        Route::get('/analysis/issuccess', 'AnalysisController@issuccess')->name('analysis.issuccess');
        Route::get('/analysis/getsuccessdata/{child_id?}', 'AnalysisController@getsuccessdata')->name('analysis.getsuccessdata');

        /*次数统计*/
        Route::get('/analysis/basecount/{child_id?}', 'AnalysisController@basecount')->name('analysis.basecount');
        Route::get('/analysis/middlecount/{child_id?}', 'AnalysisController@middlecount')->name('analysis.middlecount');
        Route::get('/analysis/highcount/{child_id?}', 'AnalysisController@highcount')->name('analysis.highcount');
        Route::get('/analysis/gettrainingdata/{type?}/{child_id?}', 'AnalysisController@gettrainingdata')->name('analysis.gettrainingdata');

        Route::get('/analysis/children', 'AnalysisController@children')->name('analysis.children');
        Route::get('/analysis/assessment/{child_id}', 'AnalysisController@assessment')->name('analysis.assessment');
        Route::get('/analysis/childsuccess/{child_id}', 'AnalysisController@childSuccess')->name('analysis.childsuccess');

    });

});

/**
 * 家长端路由。
 */
Route::group(['prefix' => 'family', 'namespace' => 'Family', 'as' => 'family.'], function () {
    /* 登录 */
    Route::get('/login', 'LoginController@index')->name('login');
    Route::post('/login', 'LoginController@login');


    Route::post('/login/sms', 'LoginController@sendSms')->name('login.sms');


    //Route::group(['middleware' => ['web', 'official.test', 'wechat.oauth:default,snsapi_userinfo']], function () {
    Route::group(['middleware' => ['family.auth']], function () {

        //首页
        Route::get('/home', 'HomeController@index')->name('home');



        Route::get('/logout', 'LoginController@logout')->name('logout');


        /*学生管理*/
        //Route::get('/child/index/{child_id}', 'ChildController@index')->name('child.index');
        Route::get('/assessment/index/{child_id}', 'AssessmentController@index')->name('assessment.index');
        Route::get('/assessment/analysis/{child_id}', 'AssessmentController@analysis')->name('assessment.analysis');
        Route::get('/assessment/ajaxdata/{child_id?}', 'AssessmentController@ajaxdata')->name('assessment.ajaxdata');

        Route::get("/training/index/{child_id}", "TrainingController@index")->name('training.index');
        Route::get("/training/view/{id}", "TrainingController@view")->name('training.view');
        Route::get('/training/ajaxdata/{child_id}', 'TrainingController@ajaxdata')->name('training.ajaxdata');
        Route::get('/training/historybygame/{child_id}', 'TrainingController@historyByGame')->name('training.historybygame');
        Route::get('/training/ajaxgamedata/{child_id}', 'TrainingController@ajaxgamedata')->name('training.ajaxgamedata');

        Route::get('/analysis/issuccess/{child_id}', 'AnalysisController@issuccess')->name('analysis.issuccess');
        Route::get('/analysis/getsuccessdata/{child_id}', 'AnalysisController@getsuccessdata')->name('analysis.getsuccessdata');
        Route::get('/analysis/trainingcount/{child_id}', 'AnalysisController@trainingcount')->name('analysis.trainingcount');
        Route::get('/analysis/gettrainingdata/{child_id}/{type?}', 'AnalysisController@gettrainingdata')->name('analysis.gettrainingdata');
    });

});



/**
 * 引入后台路由
 */
if (file_exists(__DIR__ . '/admin/web.php')) {
    include_once __DIR__ . '/admin/web.php';
}